home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / l_just.c < prev    next >
C/C++ Source or Header  |  1985-12-28  |  1KB  |  40 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ l_just - left justify a string in a buffer of a    */
  4. /*@        given length. See c_just and r_just also.   */
  5. /*@                                                    */
  6. /*@   Usage:     l_just(string, size);                 */
  7. /*@       returns the address of the modified string.  */
  8. /*@       NOTE:  There must be size+1 character        */
  9. /*@              spaces avail in string.               */
  10. /*@                                                    */
  11. /*@*****************************************************/
  12.  
  13. /***********************************************************************/
  14. /*                                                                     */
  15. /*    Left justify string str in size length field.                      */
  16. /*                                                                     */
  17. /***********************************************************************/
  18.  
  19. char *l_just(str, size)
  20. char *str;
  21. int size;
  22. {
  23.     char *s, *d;
  24.     int len, count;
  25.  
  26.     len = strlen(str);                /* get string length */
  27.  
  28.     if (len > size)                    /* truncate, if necessary */
  29.         str[size] = 0x00;
  30.     else if (len < size) {
  31.         count = size - len;            /* number of blanks to insert */
  32.         s = str + len;
  33.         while (count--)
  34.             *s++ = ' ';                /* add leading blanks */
  35.         *s = 0x00;                    /* and terminate is properly */
  36.     }
  37.  
  38.     return str;
  39. }
  40.